faApp.controller('ProductOrderDataCtrl',['$scope','simuOrderService','orderService','$location','$controller','$route','$routeParams',function($scope,simuOrderService,orderService,$location,$controller,$route,$routeParams){   

  $controller('BaseCtrl', {$scope: $scope}); 

  $scope.list = {};
  $scope.loading = true;
  $scope.pType=$routeParams.pType;
  $scope.proId=$routeParams.proId;
  $scope.config = {
    "pageSize" : 20,
    "pageNo" : 1,
    "oProjectId" : 0,
    "productId":0
  };
  
  $scope.pageChanged = function(){
    $scope.config.pageNo = $scope.pager.pageNo;
  };

  if($scope.pType=="05"){
    simuOrderService.listByProId($scope.config,$scope.proId).then(function(json){
      $scope.list = json.list;
      $scope.oType="03";
      $scope.pager = json.pager;
      $scope.loading = false;
    });
  }else if($scope.pType=="02"||$scope.pType=="03"){
    orderService.listByProId($scope.config,$scope.proId).then(function(json){
      if($scope.pType=="02"){
        $scope.oType="01";
      }else if($scope.pType=="03"){
        $scope.oType="02";
      }
      $scope.list = json.orderList;
      $scope.pager = json.page;
      $scope.loading = false;
    });
  }else if($scope.pType=="06"){
    orderService.listByProId($scope.config,$scope.proId).then(function(json){
      $scope.oType="06";
      $scope.list = json.orderList;
      $scope.pager = json.page;
      $scope.loading = false;
    });
  }


}]);
faApp.controller('editProductOrderDataCtrl',['$scope','orderPhoService','$location','$controller','$route','$routeParams',function($scope,orderPhoService,$location,$controller,$route,$routeParams){   
  $controller('BaseCtrl', {$scope: $scope}); 

  $scope.list = [];
  $scope.loading = true;
  $scope.config = {};
  $scope.config.pType=$routeParams.pType;//产品类型
  $scope.config.pId=$routeParams.pId;//产品id
  $scope.config.oId=$routeParams.oId;//订单id
  $scope.config.oType=$routeParams.oType;//订单类型
  $scope.k=$routeParams.k;//标题
  $scope.role=$routeParams.role;//角色
    $scope.head=$routeParams.head;//是否显示头部
  console.log($scope.k);

  orderPhoService.query($scope.config).then(function(json){
    $scope.list=json.list;
    $scope.loading=false;
  });

  $scope.showEstablishaFormFlag=false;

  $scope.changePic=function(v){
    $scope.pic=v;
    $scope.showEstablishaFormFlag=false;
  }
  $scope.toBack=function(v){
    $scope.oPhoId=v;
    $scope.oPhoReason="";
    $scope.showEstablishaFormFlag=true;
  }
  $scope.confirmCommit=function(v){
    $scope.config = {};
    $scope.config.id=v;
    $scope.config.oPhoStatus="03";
    orderPhoService.edit($scope.config).then(function(json){
      if(!json.statusCode){
        //alert("审核成功");
        $scope.showEstablishaFormFlag=false;
      }else{
        alert("审核失败！"+json.statusCode);
      }
      $route.reload();
    });
  }
  //全部一键通过
  $scope.confirmCommitAll=function(){
    
        angular.forEach($scope.list, function(data,index){
          $scope.config = {};
          $scope.config.id=data.oPhoId;
          $scope.config.oPhoStatus="03";
          orderPhoService.edit($scope.config).then(function(json){
            if(!json.statusCode){
              //alert("审核成功");
              $scope.showEstablishaFormFlag=false;
            }else{
              alert("审核失败！"+json.statusCode);
            }
            if((index+1) == $scope.list.length){
              $route.reload();
            }
           
          });
        });
  }
  $scope.confirmReason=function(v){
    if($scope.oPhoReason==""){
      alert("原因必填!!");
      return ;
    }
    $scope.config = {};
    $scope.config.oPhoReason=$scope.oPhoReason;
    $scope.config.id=$scope.oPhoId;
    $scope.config.oPhoStatus="04";
    orderPhoService.edit($scope.config).then(function(json){
      if(!json.statusCode){
        //alert("审核成功");
        $scope.showEstablishaFormFlag=false;
      }else{
        alert("审核失败！"+json.statusCode);
      }
      $route.reload();
    });
  }

}]);
